package com.example.myfoodrecipe.data.local

import androidx.room.*
import com.example.myfoodrecipe.data.local.entity.FavoriteEntity
import com.example.myfoodrecipe.data.local.entity.RecipeEntity
import com.example.myfoodrecipe.data.model.Result
import kotlinx.coroutines.flow.Flow

@Dao
interface RecipeDao {
    //插入数据,重复则替换
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertRecipe(recipeEntity: RecipeEntity)

    //查询数据
    @Query("select * from recipe_table where type = :type")
    fun getRecipes(type: String): Flow<List<RecipeEntity>>

    //更新数据
    @Update(onConflict = OnConflictStrategy.REPLACE)
    suspend fun updateRecipe(recipeEntity: RecipeEntity)



     //点击favFragment获取所有收藏
    @Query("select * from favorite_table")
    fun getAllFav(): Flow<List<FavoriteEntity>>

    //插入收藏食谱
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertFav(favoriteEntity: FavoriteEntity)

    //删除收藏食谱
    @Delete
    suspend fun deleteFav(favoriteEntity: FavoriteEntity)
}
